package dao.ImpI;

import bean.Thump;
import dao.SelectNumDao;
import util.DBUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class SelectNumDaoImpI implements SelectNumDao {
    Connection conn=null;
    PreparedStatement pps=null;
    DBUtil dbUtil = new DBUtil();
    @Override
    public Thump SelNum() {
        Thump thump = new Thump();
        conn = dbUtil.getConn();
        String sql="select thumpNum from thump";
        try {
            pps = conn.prepareStatement(sql);
            ResultSet resultSet = pps.executeQuery();
            while(resultSet.next()){
                thump.setNum(resultSet.getInt("thumpNum"));
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            dbUtil.close();
        }
        System.out.println("thump对象:"+thump);
        return thump;
    }

    @Override
    public boolean UpdateNum(int num) {
        conn = dbUtil.getConn();
        String sql="update thump set thumpNum=?";
        int rs = 0;
        try {
            pps = conn.prepareStatement(sql);
            pps.setInt(1,num);
            rs = pps.executeUpdate();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } finally {
            dbUtil.close();
        }
        if (rs>0) return true;
        return false;
    }
}
